# -*- coding:UTF-8 -*-
from cmdb.models import ServerRoomInfo

#机房配置数据列表
def server_room_info(start,end):
    listRes = ServerRoomInfo.objects.order_by('-id')[start:end]
    count = ServerRoomInfo.objects.all().count()
    return {'count':count, 'server_room_info_list' : listRes}

#获取所有机房信息
def get_server_rooms():
    serverRoomInfo = ServerRoomInfo.objects.all().values('id','server_room')
    return serverRoomInfo

#获取单条机房信息
def get_server_room(id):
    serverRoomInfo = ServerRoomInfo.objects.get(id=id)
    return serverRoomInfo

def add_server_room(server_room, phone, server_room_addr, comment, operator, cursor):
    room_insert_sql = 'insert into server_room_info set server_room="' + server_room + '",phone="' + phone \
                          + '",server_room_addr="' + server_room_addr + '",comment="' + comment \
                          + '",operator="' + operator + '"'
    cursor.execute(room_insert_sql)
    return cursor.lastrowid

def update_server_room(id, server_room, phone, server_room_addr, comment, operator, cursor):
    room_insert_sql = 'update server_room_info set server_room="' + server_room + '",phone="' + phone \
                      + '",server_room_addr="' + server_room_addr + '",comment="' + comment \
                      + '",operator="' + operator + '" where id=' + id
    cursor.execute(room_insert_sql)

def del_server_room(id, cursor):
    server_room_del = 'delete from server_room_info where id=' + id
    cursor.execute(server_room_del)
